@extends('agent.mainlayout')
@section('title')
    <div class="title"><span>发布公告</span></div>
    @endsection
    @section('content')
    <div class="five">
        <div class="header" id="tanchuang" style="cursor:pointer;width: 90px;text-align: center;background: #36bc9b;padding: 8px 0;color: white;display: inline-block;">发布公告</div>

        @if(count($errors)>0)
            <div style="color:#F00;display: inline-block;margin-left: 250px;">
                @if(is_object($errors))
                    @foreach($errors->all() as $v)
                        {{$v}}
                    @endforeach
                @else
                    <p>{{$errors}}</p>
                @endif
            </div>
        @endif

        <table id="kuxuan">
            <tr>
                <th>序号</th>
                <th>标题</th>
                <th>内容</th>
                <th>时间</th>
                <th>详情</th>
                <th>操作</th>
            </tr>
            @if(!empty($res['data']))
                @foreach($res['data'] as $v)
            <tr>
                <td>{{$v['id']}}</td>
                <td>{{$v['title']}}</td>
            @if(strlen($v['content'])>24)
                <td>{{mb_substr($v['content'],0,10)}}...</td>
            @else
                <td>{{$v['content']}}</td>
            @endif
                <td>{{$v['created_at']}}</td>
                <td style="cursor: pointer;" onclick="fn('{{$v['content']}}');">查看详情</td>
                <td style="cursor: pointer;color: red;" onclick="del('{{$v['id']}}');">删除</td>
            </tr>
                @endforeach
                @else
            <tr>
                <td colspan="6">暂无公告...</td>
            </tr>

            @endif

        </table>
        @if($res['last_page']>1)
        <div class="del">
            <div class="bot">
                @if($res['prev_page_url'])
                    <p class="prev"><a href="{{$res['prev_page_url']}}">上一页</a></p>
                @endif
                <ul>
                    @foreach($res['pageNoList'] as $v)
                        <li @if($res['current_page'] ==  $v )class="active_list" @endif ><a href="/center/announce/agent?page={{$v}}">{{$v}}</a></li>
                    @endforeach
                </ul>
                @if($res['next_page_url'])
                    <p class="next"><a href="{{$res['next_page_url']}}">下一页</a></p>
                @endif
            </div>
        </div>
        @endif
    </div>
    <div id="fixed" style="display: none">
    <!-- start 发布公告-->
    <form action="{{url('center/announceag/add')}}" method="post" id="form1">
    <div class="fixed_six" id="fixed_six" style="display: none">
        <h3>发布公告</h3>
        <div class="one">
            <p>发布对象</p>
            <select name="type">
                <option value="1">所有人</option>
                <option value="2">品牌商</option>
                <option value="3">代理商</option>
            </select>
        </div>
        <div class="one">
            <p>标题</p>
            <input type="text" name="title"/>
        </div>
        <div class="two">
            <p>内容</p>
            <textarea name="content"></textarea>
        </div>
        <div class="footer">
            <p id="fabu">发布</p>
            <p id="quxiao">取消</p>
        </div>
    </div>
    </form>
        <!-- end 发布公告-->
    </div>
@endsection

<script>
    //删除公告
    function del(id){

        layer.confirm('确定要删除该项吗?',{btn:['确定','取消']},function(){

            layer.closeAll();
            layer.load(2, {shade: false});
            $.ajax({
                type:'post',
                url:"{{urlAdmin('AnnounceAg','postAnnounceDel')}}",
                data:{'id':id,'_token':'{{csrf_token()}}'},
                dataType:'json',
                success: function (res) {
                    layer.closeAll();
                    // alert(res);
                    if(res['status']==1){

                        layer.msg(res.msg,{icon:6});
                        setTimeout("location.reload()",1500);

                    }else{

                        layer.msg(res.msg,{icon:5});

                    }

                }

            });

        },function(){

            layer.msg('已取消了!');

        });
    }


    //查看详情
    function fn(a){

        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '240px'], //宽高
            content: a
        });

    }
    window.onload = function () {
        /****酷炫效果*****/
        var oTable = document.getElementById('kuxuan');
        var aLi = oTable.getElementsByTagName('tr');
        //var arr = ['red','blue','grey'];
        var str = '';
        for(var i=1;i<aLi.length;i++){

            //aLi[i].style.background = arr[i%3];

            aLi[i].onmouseover = function(){
                str = this.style.background;      //将原来的颜色保存起来
                this.style.background = '#2bdacf';
            }

            aLi[i].onmouseout = function(){
                this.style.background = str;
            }

        }
        /****酷炫效果******/



        /*********快闪重定向*********/
        var message = "{{Session::get('message')}}";
        $(window).ready(function () {
            if (message) {
                layer.msg(message, {
                    time: 3000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        });
        /*********快闪重定向*********/

    document.getElementById('tanchuang').onclick = function(){

    document.getElementById('fixed').style.display = 'block';
    document.getElementById('fixed_six').style.display = 'block';

    }


    document.getElementById('fabu').onclick = function(){

    document.getElementById('fixed').style.display = 'none';
    document.getElementById('fixed_six').style.display = 'none';
    document.getElementById('form1').submit();

    }


    document.getElementById('quxiao').onclick = function(){

    document.getElementById('fixed').style.display = 'none';
    document.getElementById('fixed_six').style.display = 'none';

    }






}



</script>